﻿@using Admin.Models
@using Admin.Models.BlackList
@using Admin.Models.Chart
@{
    ViewBag.Title = "黑名单管理";
}

 @(Html.Kendo().Grid<BlackListViewModel>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Command(command => { command.Edit(); command.Destroy(); }).Width(100);
        columns.Bound(p => p.CardType).Filterable(false).Width(100).ClientTemplate("#=CardType.Name#");
        columns.Bound(p => p.CardNo).Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(false))).Width(140);
        columns.Bound(p => p.PatientName).Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(false))).Width(120);
        columns.Bound(p => p.IdenNo).Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(false))).Width(150);
        columns.Bound(p => p.Phone).Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(false))).Width(120);
        columns.Bound(p => p.CancelCount).Filterable(false).EditorTemplateName("Integer").Width(120);
        columns.Bound(p => p.CancelYear).Filterable(false).EditorTemplateName("Integer").Width(120);
        columns.Bound(p => p.CancelMonth).Filterable(false).EditorTemplateName("Integer").Width(120);
    })
    .ToolBar(tools =>
    {
        tools.Create();
        tools.Excel().Text("导出");
    } )
    .Excel(excel => excel
    .FileName("黑名单.xlsx")
    .Filterable(true)
    .ProxyURL(Url.Action("Excel_Export_Save", "Grid"))
    )
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .HtmlAttributes(new { style = "height:550px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Events(events => events.Error("error_handler"))
        .Model(model => {
            model.Id(p => p.Id);
            model.Field(p => p.Id).Editable(false);
            model.Field(p => p.CardType).DefaultValue( ViewData["defaultCardType"] as CardType);
        })
        .Create(update => update.Action("BlackList_Create", "Grid"))
        .Read(read => read.Action("BlackLists_Read", "Grid"))
        .Update(update => update.Action("BlackList_Update", "Grid"))
        .Destroy(update => update.Action("BlackList_Destroy", "Grid"))
    )
)
<script type="text/javascript">
    function error_handler(e) {
        if (e.errors) {
            var message = "Errors:\n";
            $.each(e.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function() {
                        message += this + "\n";
                    });
                }
            });
            alert(message);
        }
    }

    function getCardType(cardType) {
       var  _cardType = "";
        switch(cardType) {
            case 0:
                _cardType = "诊疗卡";
                break;
            case 1:
                _cardType = "健康卡";
                break;
            default:
                _cardType = "其他";
                break;
       }
        return _cardType;
    }
</script>
    <script>
        $(".sidebar-menu li").removeClass("active");
        $("#blackList").addClass("active");
    </script>
